cmake_minimum_required(VERSION 3.15)

project(mini_redis LANGUAGES CXX)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

option(MINI_REDIS_ENABLE_WARNINGS "Enable compiler warnings" ON)
find_package(Threads REQUIRED)

if(MINI_REDIS_ENABLE_ENABLE_WARNINGS)
  if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    add_compile_options(-Wall -Wextra -Wpedantic -Wconversion)
  elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
    add_compile_options(/W4)
  endif()
endif()

if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Release")
  add_compile_options(-O3 -DNDEBUG)
endif()

file(GLOB_RECURSE SRC_FILES "src/*.cpp")

add_executable(mini_redis ${SRC_FILES})

target_compile_definitions(mini_redis PRIVATE $<$<CONFIG:Debug>:MINI_REDIS_DEBUG=1>)

target_include_directories(mini_redis PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)

install(TARGETS mini_redis RUNTIME DESTINATION bin)

target_link_libraries(mini_redis PRIVATE Threads::Threads)
